#include <iostream>
using namespace std;

//https://ac.nowcoder.com/acm/problem/16693

int v;
int n;

int vol[40];
long long dp[40][20010];

int main()
{
    cin >> v >> n;

    for (int i = 1; i <= n; i++) cin >> vol[i];

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= v; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j >= vol[i])
                dp[i][j] = max(dp[i][j], dp[i- 1][j - vol[i]] + vol[i]);
        }
    }

    cout << v - dp[n][v] << endl;;

    return 0;
}
